package com.app.newiptv.bean;

import android.os.Parcel;
import java.util.HashMap;
import java.util.Map;

/**
 * 影片数据封装
 *
 * @author Richard
 */
public class Item extends Content {
    /**
     * 上次已播放的地方
     */
    public int seekPosition;
    /**
     * 上次播放的集数
     */
    public int episodePosition;
    /**
     * 最新更新
     */
    public String lastUpdateEpisode;

    public Item() {
        this("", "", "", new ImageSource(), "");
    }

    public Item(String parentID, String contentID, String name, ImageSource imageSource, String type) {
        super(parentID, contentID, name, imageSource, type);
        lastUpdateEpisode = "";
    }

    @Override
    public int hashCode() {
        return 1;
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || !(o instanceof Item)) {
            return false;
        }
        Item tmpItem = (Item) o;
        return tmpItem.contentID.equals(contentID);
    }

    // ---------------------Parcelable implements------------


    @Override
    public String toString() {
        return "Item{" +
                "type=" + type +
                ", lastVisitDate=" + lastVisitDate +
                ", seekPosition=" + seekPosition +
                ", episodePosition=" + episodePosition +
                ", lastUpdateEpisode='" + lastUpdateEpisode + '\'' +
                '}';
    }

    public static final Creator<Item> CREATOR = new Creator<Item>() {
        @Override
        public Item createFromParcel(Parcel source) {
            String parentID = source.readString();
            String contentID = source.readString();
            String name = source.readString();
            ImageSource imgSource = source.readParcelable(ImageSource.class.getClassLoader());
            String type = source.readString();
            Map extras = source.readHashMap(HashMap.class.getClassLoader());
            long lastVisitDate = source.readLong();
            int seekPosition = source.readInt();
            int episodePosition = source.readInt();
            String lastUpdateEpisode = source.readString();
            int isHostory = source.readInt();

            Item item = new Item(parentID, contentID, name, imgSource, type);
            item.lastVisitDate = lastVisitDate;
            item.seekPosition = seekPosition;
            item.episodePosition = episodePosition;
            item.lastUpdateEpisode = lastUpdateEpisode;
            item.extras = extras;
            item.isHistory = isHostory;
            return item;
        }

        @Override
        public Item[] newArray(int size) {
            return new Item[size];
        }
    };

    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(parentID);
        dest.writeString(contentID);
        dest.writeString(name);
        dest.writeParcelable(imgSource, flags);
        dest.writeString(type);
        dest.writeMap(extras);
        dest.writeLong(lastVisitDate);
        dest.writeInt(seekPosition);
        dest.writeInt(episodePosition);
        dest.writeString(lastUpdateEpisode);
        dest.writeInt(isHistory);
    }
}
